package cmd

import (
	"gitee.com/xuender/oils/logs"
	"gitee.com/xuender/se"
	"github.com/spf13/cobra"
)

// nolint: gochecknoinits
func init() {
	searchCmd := &cobra.Command{
		Use:     "search [关键字]",
		Short:   "搜索关键字",
		Long:    `搜索关键字显示包含关键字的文件及位置`,
		Aliases: []string{"s"},
		Run: func(cmd *cobra.Command, args []string) {
			if len(args) == 0 {
				logs.Error("缺少关键字")
				_ = cmd.Usage()

				return
			}

			app := se.InitApp(se.NewContext(cmd))
			defer app.Close()

			app.Search(args)
		},
	}

	searchCmd.Flags().Uint("limit", 100, "显示条数")
	searchCmd.Flags().Uint("offset", 0, "起始条数")

	rootCmd.AddCommand(searchCmd)
}
